//
//  LSZAddressBookVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/11/11.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZAddressBookVC.h"

@interface LSZAddressBookVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tabAddressBook;
@property(nonatomic,strong) LSZCommunicationDataManager * communicationDataManager;
@end

@implementation LSZAddressBookVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([NullStringjudgment(NSStr([_MyCenter branchName])) isEqualToString:@""]) {
        [LSZRequestData initWithPersonalCenter:^(BOOL ISoK, NSString * string, NSDictionary * dic) {
            if (ISoK == YES) {
                self.title = [_MyCenter branchName];
            }else{
                if ([string isEqualToString:@"重复登录"]) {
                    [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZStudyPlanViewController"];
                }else{
                    [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
                }
            }
        }];
    }else{
        self.title = [_MyCenter branchName];
    }
    [self.tabAddressBook registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    if ([(NullStringjudgment(NSStr([_UserM villageID]))) isEqualToString:@""]) {
        [self initGetMyVillage];
    }else{
        [self initWithBranchAcquisition];
    }
}
-(void)initGetMyVillage
{
    [LSZRequestData initResGetMyVillage:^(BOOL isOK, NSString * string, NSDictionary * dic) {
        if (isOK == YES) {
            [self initWithBranchAcquisition];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZStudyPlanViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)initWithBranchAcquisition
{
    [LSZRequestDicData initBranchAcquisition:NullStringjudgment(NSStr([_UserM villageID])) :^(BOOL isOK, NSString * string, LSZCommunicationDataManager * communicationDataManager) {
        if (isOK == YES) {
            self.communicationDataManager = communicationDataManager;
            [self.tabAddressBook reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZStudyPlanViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }

    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.communicationDataManager.arrayData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    if (self.communicationDataManager.arrayData.count > indexPath.row
        ) {
        LSZCommunicationDataMg * mg = nil;
        mg = self.communicationDataManager.arrayData[indexPath.row];
        cell.textLabel.text = mg.name;
        cell.textLabel.textColor = RGBColor(51, 51, 51);
        cell.textLabel.font = FONT_(14);
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.communicationDataManager.arrayData.count > indexPath.row
        ) {
        LSZCommunicationDataMg * mg = nil;
        mg = self.communicationDataManager.arrayData[indexPath.row];
        if ([mg.leaf isEqualToString:@"false"]) {
            LSZSecondaryCommunicationDataVC * vc = [[LSZSecondaryCommunicationDataVC alloc]init];
            vc.communicationDataMg = mg;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            LSZAddressBookViewController * vc = [[LSZAddressBookViewController alloc]init];
            vc.communicationDataMg = mg;
            [self.navigationController pushViewController:vc animated:YES];
        }
 
    }
}
-(UITableView *)tabAddressBook
{
    if (_tabAddressBook == nil) {
        _tabAddressBook = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height) style:UITableViewStylePlain];
        _tabAddressBook.delegate = self;
        _tabAddressBook.dataSource = self;
        _tabAddressBook.estimatedRowHeight=0;
        _tabAddressBook.estimatedSectionFooterHeight =0;
        _tabAddressBook.estimatedSectionHeaderHeight =0;
        [_tabAddressBook setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tabAddressBook];
    }
    return _tabAddressBook;
}


@end
